package cn.merryyou.jpa.domain;


import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Data
@Entity
@Table
@NoArgsConstructor
public class RedPackage implements Serializable {

    private static final long serialVersionUID = -7406480542274357950L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private double amount;
    @Column(name = "residual_amount")
    private double residualAmount;
    @Column(name = "create_time")
    private Date createTime;
    @OneToMany(mappedBy = "user",cascade = CascadeType.ALL)
    private Set<UserPackage> userPackages = new HashSet<>();

    public RedPackage(double amount, Date createTime) {
        this.amount = amount;
        this.createTime = createTime;
    }

    public RedPackage(double amount) {
        this.amount = amount;
        this.createTime = new Date();
    }

}
